var app = require('../app');
$("#closepage").on('click',function(){

    window.location.href = '/expirecases/index';

});
var lockfas = false,
    case_status = 0,
    scene_type = null,
    case_code = null,
    begin_date = null,
    end_date = null,
    url = '';
var winHeight = $(window).height() -310,
winHeight2 = $(window).height() -270;
$(".with-window").css("height",winHeight);
$(".with-window2").css("height",winHeight2); 
$(window).resize(function() { 
    winHeight = $(window).height() -310;
    winHeight2 = $(window).height() -270;
    $(".with-window").css("height",winHeight);
    $(".with-window2").css("height",winHeight2); 
});
$('[role-click=filter]').on('click', function(){
    case_status = $('[role-ele=status]').val();
    case_code = $("input[name=case_code]").val();
    begin_date = $("input[name=begin_date]").val();
    end_date = $("input[name=end_date]").val();
    url = "/expirecases/index?case_status="+case_status+"&case_code="+case_code+"&begin_date="+begin_date+"&end_date="+end_date;
    window.location.href = url;
})

$('[role-click=export]').on('click', function(){
    case_status = $('[role-ele=status]').val();
    case_code = $("input[name=case_code]").val();
    begin_date = $("input[name=begin_date]").val();
    end_date = $("input[name=end_date]").val();
    url = "/expirecases/export?case_status="+case_status+"&case_code="+case_code+"&begin_date="+begin_date+"&end_date="+end_date;
    window.location.href = url;
})
var pageStatus = window.location.search.slice(-1);
if(pageStatus == 1){
    $('.page-top-left-btn').removeClass("left-btn-checked");
    $('.page-top-left-btn-course').addClass('left-btn-checked');
    $('.box-main4,.box-main3,.context-box-main').css('display','none');
    $('.box-main4').css('display','flex');
}
$('.progress-node').each(function(){
        if($(this).attr('isShow') == 1){
        $(this).css('color','#1e93f5')
        $(this).find('.progress-node-point').css('background','#1e93f5')
    }else{
        $(this).css('color','#ccc')
        $(this).find('.progress-node-point').css('background','#ccc')
    }
});
$('.progress-node-line').each(function(){
        if($(this).attr('isShow') == 1){
        $(this).css('border-left','2px solid #1e93f5')
        
    }else{
        $(this).css('border-left','2px solid #ccc')
    }
});
$('.page-top-left-btn').on('click',function(){
    $(this).addClass('left-btn-checked').siblings().removeClass("left-btn-checked");
    $('.box-main4,.box-main3,.context-box-main').css('display','none')
    if($(this).attr('type') == "1"){
        $('.box-main1').css('display','block')
    }else if($(this).attr('type') == "3"){
        $('.box-main2').css('display','block')
    }else if($(this).attr('type') == "2"){
        $('.box-main3').css('display','flex')
    }else if($(this).attr('type') == "4"){
        $('.box-main4').css('display','flex')
    }
})

var  defaultFileSrc = $('.caseCheckInfo-main-nav-li').eq(0).attr('filepath')
$('.showFile').attr('src',defaultFileSrc);
$('.caseCheckInfo-main-nav-li').on('click',function(){
    var fileSrc = $(this).attr('filepath')
    $('.showFile').attr('src',fileSrc)
    $('.caseCheckInfo-main-nav-li-img-box').removeClass('caseCheckInfo-main-nav-li-img-box-checked');
    $('.caseCheckInfo-main-nav-li-name').removeClass('caseCheckInfo-main-nav-li-name-checked');
    $(this).children(".caseCheckInfo-main-nav-li-img-box").addClass('caseCheckInfo-main-nav-li-img-box-checked');
    $(this).children(".caseCheckInfo-main-nav-li-name").addClass('caseCheckInfo-main-nav-li-name-checked');
})

$('body')
    .on('click','#fpclosebtn,#fpModalClose', function(){
        $('.casesure').hide();
        $('.modal-box').hide();
        $('#yqModal').hide();
    })
    //单个分配
    .on('click','.yqbtn', function(){
        $('.casesure').show();
        $('.mobile-p').hide();
        $('#yqModal').show()
        $('.distribution').attr('case_id',$(this).attr('yqid'));
    })
    //确认
    .on('click','.distribution', function(){
        var case_id = $(this).attr('case_id');
        var times = $('#delayTime').val();
        if(!times){
            toastr.success('请选择延期时间');
            return false;
        }
        if(lockfas)return;
        lockfas = true;
        $.ajax({
            url: '/expirecases/delayCase',
            type: 'post',
            data: {
                'case_id': case_id,
                'delayTime':times
            },
            dataType: "json",
            success: function(res){
                if(res.code == 200){
                    toastr.success('延期成功');
                    setTimeout(function(){
                        window.location.reload();
                    },3000);

                }else{
                    toastr.error(res.message);
                    lockfas = false;
                }
            },
            error: function(err){
                toastr.error('网络错误,请稍后重试');
                lockfas = false;

            }
        })
    })
